Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use go list to analyze stdlib imports #12368

Merged
merged 3 commits into from
Jul 17, 2021

Conversation

tdyas
Copy link
Contributor

@tdyas tdyas commented Jul 16, 2021

Problem

As described in #11910, the current version of the experimental Go plugin parses the directory structure of the Go distribution to determine the imports provided by the standard library. go list already provides this information in JSON form when asked. This was also how the v1 plugin obtained the same information.

Solution

Use go list to obtain import paths for the standard library. This PR introduces the base class ResolvedImportPaths which will be inherited by all types that represent import path mappings. The first use of this base class is for the ResolvedImportPathsForGoLangDistribution dataclass which represents analysis of the Go standard library.

Testing

Added integration test for the import analysis and the first-party build integration test continues to pass.

Closes #11910.

[ci skip-rust]

[ci skip-rust]

[ci skip-build-wheels]
@tdyas tdyas added the backend: Go Go backend-related issues label Jul 16, 2021
@tdyas
Copy link
Contributor Author

tdyas commented Jul 16, 2021

The ijson package was added in order to be able to parse the JSON output of go list which returns multiple top-level JSON objects. The Python json stdlib module cannot parse that output easily.

Should I add ijson in a separate PR?

[ci skip-rust]

[ci skip-build-wheels]
Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks Tom.

src/python/pants/backend/go/build.py Outdated Show resolved Hide resolved
3rdparty/python/requirements.txt Show resolved Hide resolved
[ci skip-rust]

[ci skip-build-wheels]
@tdyas tdyas merged commit 40469dc into pantsbuild:main Jul 17, 2021
@tdyas tdyas deleted the golang_grok_goroot_via_tooling branch July 17, 2021 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: Go Go backend-related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use go list to obtain the standard library's package mapping
2 participants